package IO.Buffered.BufferedStream;

import java.io.*;

/*
 * 使用缓冲流完成复制操作
 *
 * */
public class CopyDemo1 {
    public static void main(String[] args) {
        copy("C:\\Users\\20918\\Pictures\\aaa.png", "D:\\aaa\\bbb\\aaa.png");
    }

    public static void copy(String srcPath, String destPath) {
        try (FileInputStream fis = new FileInputStream(srcPath);
             FileOutputStream fos = new FileOutputStream(destPath);
            //把低级流封装成高级流
             InputStream bis = new BufferedInputStream(fis);//8192个字节==8g
             OutputStream bos = new BufferedOutputStream(fos);
        ) {
            byte[] buffer = new byte[1024];
            int len;
            while ((len = bis.read(buffer)) != -1) {
                bos.write(buffer, 0, len);//通道交互的次数少了，性能大量提升
            }
        } catch (IOException e) {
            e.printStackTrace();
        }


    }
}
